import BaseRV2Api from '@/framework/infra/base/BaseRV2Api'

export default class BaseCURDV2Api extends BaseRV2Api {
  // 更新接口方法
  update(updateParam) {
    let params = {...updateParam}
    if (updateParam.roleIdList) {
      params =  { ...updateParam, roleIdList: undefined, roleList: updateParam.roleIdList?.map(v => ({ id: v}))}
    }
    return this.post('update', params)
  }

  create(createParam) {
    let params = {...createParam}
    if (createParam.roleIdList) {
      params =  { ...createParam, roleIdList: undefined, roleList: createParam.roleIdList?.map(v => ({ id: v}))}
    }
    return this.post('create', params)
  }

  remove(id) {
    return this.post('remove', { id })
  }

  removeMany(ids, propList) {
    return this.post('remove-many', {ids, propList})
  }

  online = (id) => this.request.post(this.absUrl('online'), {id})
  offline = (id) => this.request.post(this.absUrl('offline'), {id})
  batchOffline = (ids) => this.request.post(this.absUrl('batch-offline'), {ids})
  batchOnline = (ids) => this.request.post(this.absUrl('batch-online'), {ids})

  check({checkStatus, checkRemark = '', idList, ...data}) {
    return this.post('check', {
      ...data,
      status: checkStatus === 5 ? 1 : 0, remark: checkRemark, id: idList[0], idList
    })
  }

}
